import tester.cobertura.Instrument;

/**
 * @author Adam Blackwell & Ryan Cassidy
 */
// to represent a checking account in a bank
@Instrument 
public class Checking extends AAccount {

	public int minimum; // The minimum amount a customer is allowed to have

	// in the account at any particular point in time.

	public Checking(int accountNum, int balance, String name, int minimum) {
		super(accountNum, balance, name);
		this.minimum = minimum;
	}

	/*
	 * TEMPLATE: FIELDS: ... accountNum ... -- int ... balance ... -- int ...
	 * name ... -- String ... minimum ... -- int
	 * 
	 * METHODS: ... deposit(int amt) ... -- IAccount ... withdraw(int amt) ...
	 * -- IAccount
	 */

	// produce an updated account after depositing the given amount
	@Override
	public IAccount deposit(int amt) {
		return new Checking(this.accountNum, this.balance + amt, this.name,
				this.minimum);
	}

	// produce an updated account after withdrawing the given amount
	@Override
	public IAccount withdraw(int amt) {
		if (this.balance - this.minimum >= amt) {
			return new Checking(this.accountNum, this.balance - amt, this.name,
					this.minimum);
		} else {
			throw new RuntimeException(
					"Insufficient Funds in the checking account.");
		}
	}

	@Override
	// Checks if this account is a Checking account (It is).
	public boolean isChecking() {
		return true;
	}

	@Override
	// Turns the account into a Checking account.
	public Checking toChecking() {
		return this;
	}

	// @Override
	// // Checks if two accounts are the same.
	// public boolean same(IAccount that) {
	// if(that.isChecking()){
	// return that.toChecking().sameChecking(this);
	// } else {
	// return false;
	// }
	// }

	// Use instance of.
	@Override
	// Checks if two accounts are the same.
	public boolean same(IAccount that) {
		if (that instanceof Checking) {
			return ((Checking) that).sameChecking(this);
		} else {
			return false;
		}
	}

	// Compares the fields of two Checking accounts.
	protected boolean sameChecking(Checking that) {
		return this.name.equals(that.name) && this.minimum == that.minimum
				&& this.balance == that.balance
				&& this.accountNum == that.accountNum;
	}

	// Checks if this account is a PremiumChecking account
	@Override
	public boolean isPremiumChecking() {
		return false;
	}
}
